import {LibraryType} from "../../ElementLibraryTypes";
import {eventBus} from "../../../../../../eventbus/eventbus";
import elementLibraryManager from "../../ElementLibraryManager";

/**
 * @type {LibraryItem|null}
 */
let curItem = null;

const createElementLibraryFolder = {
  validate(_, item) {
    curItem = item;
    return item?.libraryType === LibraryType.FOLDER;
  },
  execute() {
    if (!curItem) {
      return;
    }
    eventBus.emit("openElementLibraryFolder", curItem.id);
    elementLibraryManager.preCreateFolder(curItem);
  }
}

export default createElementLibraryFolder;